var express = require('express');
let db = require('../model/db');
var router = express.Router();
 
//查询
function chaxun(){
  let selectAll = 'select * from admin';
  let connection = db.connection();
  db.select(connection, selectAll, '',function(data){
    console.log(data);
    return data;
    
  })
}
//插入
function charu(){
    let project = {adminname: 'test', password: '99999'};
    let sqlString = 'INSERT INTO admin set ? ';
    let connection = db.connection();
    db.insert(connection, sqlString, project, function(id){
        console.log('inserted id is:' + id);
    });
    db.close(connection);
    // res.send('操作成功');
}
//删除
function del(id){
  let sql = 'delete from `admin` where id = '+ id;
  let connection = db.connection();
  db.delete(connection, sql, function(data){
    console.log(data);
  })
}
//更新
function update(){
  let sql = 'update `admin` set salt = "ererere" where id = 22';
  let connection = db.connection();
  db.update(connection, sql, function(data){
    console.log(data)
  })
}


/* GET users listing. */
router.get('/', function(req, res, next) {
  update();
  res.json([{a:1,V:2},{a:5,V:8},{a:'哈哈好大好大',V:'哈克哈打哈电话 '}]);
  res.end('success');
});




module.exports = router;
